<?php

namespace App\Http\Controllers\Admin\Persons;

use Illuminate\Http\Request;
use App\Http\Controllers\AdminController;

use App\Models\User;

class PersonController extends AdminController
{
     /**
     * 获取列表数据
     * @return [type] [description]
     */
    function getLists(Request $request){
    	$pageIndex = (int)$request->input('page') ?  $request->input('page') : 1;
    	$length = 10;
    	$start = ($pageIndex-1)*$length;

    	$where = [];

        $usermodel = User::where($where);

        $phone = $request->input('phone');
        if($phone){
            $usermodel->where('phone','like',"%$phone%");
        }

    	$data['total'] = $usermodel->count();
    	if($data['total']>0){
    		$users = $usermodel->orderBy('created_at','desc')->skip($start)->take($length)->get();
            foreach ($users as $user) {
                $data['result'] [] = [
                    'headimgurl' => 'upload/'.$user->headimgurl,
                    'phone' => $user->phone,
                    'created_at' => $user->created_at->format('Y-m-d H:i:s'),
                ];  
            }
            
    	}
    	$this->ajaxJson(0,'',$data);
    }
}
